//
//  MyViewController.swift
//  SheYangBigData
//
//  Created by 叁拾叁 on 2021/4/7.
//  Copyright © 2021 叁拾叁. All rights reserved.
//

import UIKit

class MyViewController: SYBaseViewController {
    
    let topmgView: UIImageView = {
        let v = UIImageView()
        v.image = UIImage(named: "my_top")
        return v
    }()
    
    var bgView: UIView = {
        let v = UIView()
        v.layer.cornerRadius = 5.autoWidth()
        v.backgroundColor = UIColor.white
        v.layer.shadowColor = UIColor(hex: 0x0078FF).cgColor
        v.layer.shadowOpacity = 0.5//阴影透明度
        v.layer.shadowOffset = CGSize(width: 0, height: -5)///阴影偏移量,四周
        v.layer.shadowRadius = 5//阴影半径  shadowPathWidth：阴影宽度
        return v
    }()
    
    let name: UILabel = {
        let v = UILabel()
        v.text = "这里什么都没有哦"
        v.font = 19.autoFontSize()
        v.textColor = UIColor(hex: 0x121212)
        return v
    }()
    
    let zhiwu: UILabel = {
        let v = UILabel()
        v.text = "这里什么都没有哦"
        v.font = 13.autoFontSize()
        v.textColor = UIColor(hex: 0x0078FF)
        return v
    }()
    
    let bumen: UILabel = {
        let v = UILabel()
        v.text = "这里什么都没有哦"
        v.font = 13.autoFontSize()
        v.textColor = UIColor(hex: 0x666666)
        return v
    }()
    
    let headImgView: UIImageView = {
        let v = UIImageView()
        v.image = UIImage(named: "my_head")
        return v
    }()
    
    public var lineView: UIView = {
        let v: UIView = UIView()
        v.backgroundColor = UIColor(hex: 0xE6E6E6)
        return v
    }()
    
    var shoujihao: CGQmyView = {
        let v = CGQmyView()
        v.tipText.text = "手机号"
        v.imgView.sy_name("shouji_icon")
        v.arrow.isHidden = true
        return v
    }()
    
    var youxiang: CGQmyView = {
        let v = CGQmyView()
        v.tipText.text = "邮箱"
        v.imgView.sy_name("youxiang_icon")
        v.arrow.isHidden = true
        return v
    }()
    
    var xiugai: CGQmyView = {
        let v = CGQmyView()
        v.tipText.text = "修改密码"
        v.imgView.sy_name("zhanghao_icon")
        return v
    }()
    
    var yijian: CGQmyView = {
        let v = CGQmyView()
        v.tipText.text = "意见反馈"
        v.imgView.sy_name("yijian_icon")
        return v
    }()
    var delete: UIButton = {
        let v = UIButton()
        v.setTitle("退出", for: .normal)
        v.setTitleColor(UIColor(hex: 0x0782FF), for: .normal)
        v.titleLabel?.font = 18.autoFontSize()
        v.layer.cornerRadius = 3
        v.layer.masksToBounds = true
        v.backgroundColor = UIColor(hex: 0xF7F7F7)
        return v
    }()
    


    override func viewWillAppear(_ animated: Bool) {
        
        self.tabBarController?.tabBar.isHidden = false
        self.navigationItem.leftBarButtonItems = []
    }
 
    override func viewDidLoad() {
        super.viewDidLoad()

        self.title = "我的"
        
        initViews()
        let defaults = UserDefaults.standard
        name.text = defaults.object(forKey: "trueName") as? String
        zhiwu.text = defaults.object(forKey: "roleList") as? String
        bumen.text = defaults.object(forKey: "deptList") as? String
        let urlStr: String = (defaults.object(forKey: "headImg") as? String) ?? ""
        headImgView .sy_setWithUrl(urlStr, "my_head")
        shoujihao.subTitle.text = defaults.object(forKey: "mobile") as? String
        youxiang.subTitle.text = defaults.object(forKey: "email") as? String

    }
    
    func initViews() {
        
        yijian.tixianBt.addAction {[weak self] in
            if let `self` = self {
                
                let vc = CGQfankuiViewController()
                
                
                self.sy_push(vc)
            }
        }
       
        
        xiugai.tixianBt.addAction {[weak self] in
            if let `self` = self {
                let vc = CGQxiugaimimaViewController()
                self.sy_push(vc)
            }
        }
     
        
        delete.addAction {[weak self] in
            if let `self` = self {
                
                self.clearAllUserDefaultsData()
                SYTokenCheck.toLoginVC()

            }
        }
        self.view.addSubview(delete)
        self.view.addSubview(topmgView)
        self.view.addSubview(bgView)
        self.view.addSubview(name)
        self.view.addSubview(zhiwu)
        self.view.addSubview(bumen)
        
        self.view.addSubview(headImgView)
        self.view.addSubview(lineView)
        self.view.addSubview(yijian)
        self.view.addSubview(shoujihao)
        self.view.addSubview(youxiang)
        self.view.addSubview(xiugai)
        
        topmgView.snp.makeConstraints { (make) in
            make.top.equalToSuperview().offset(NAV_HEIGHT)
            make.left.equalToSuperview()
            make.right.equalToSuperview()
            make.height.equalTo(146.autoWidth())
        }
        bgView.snp.makeConstraints { (make) in
            make.top.equalToSuperview().offset(58.autoWidth()+NAV_HEIGHT)
            make.left.equalToSuperview().offset(10.autoWidth())
            make.right.equalToSuperview().offset(-10.autoWidth())
            make.height.equalTo(135.autoWidth())
        }
        name.snp.makeConstraints { (make) in
            make.top.equalToSuperview().offset(83.autoWidth()+NAV_HEIGHT)
            make.left.equalToSuperview().offset(25.autoWidth())
            make.right.equalToSuperview()
            make.height.equalTo(18.autoWidth())
        }
        zhiwu.snp.makeConstraints { (make) in
            make.top.equalToSuperview().offset(120.autoWidth()+NAV_HEIGHT)
            make.left.equalToSuperview().offset(25.autoWidth())
            make.right.equalToSuperview()
            make.height.equalTo(13.autoWidth())
        }
        bumen.snp.makeConstraints { (make) in
            make.top.equalToSuperview().offset(140.autoWidth()+NAV_HEIGHT)
            make.left.equalToSuperview().offset(25.autoWidth())
            make.right.equalToSuperview()
            make.height.equalTo(13.autoWidth())
        }
        headImgView.snp.makeConstraints { (make) in
            make.top.equalToSuperview().offset(75.autoWidth()+NAV_HEIGHT)
            make.right.equalToSuperview().offset(-25.autoWidth())
            make.width.height.equalTo(83.autoWidth())
        }
        lineView.snp.makeConstraints { (make) in
            make.top.equalToSuperview().offset(171.autoWidth()+NAV_HEIGHT)
            make.left.equalToSuperview().offset(25.autoWidth())
            make.right.equalToSuperview().offset(-25.autoWidth())
            make.height.equalTo(0.5.autoWidth())
        }
        shoujihao.snp.makeConstraints { (make) in
            make.top.equalToSuperview().offset(200.autoWidth()+NAV_HEIGHT)
            make.left.equalToSuperview()
            make.right.equalToSuperview()
            make.height.equalTo(48.autoWidth())
        }
        youxiang.snp.makeConstraints { (make) in
//            make.top.equalToSuperview().offset(296.autoWidth()+NAV_HEIGHT)
            make.top.equalTo(shoujihao.snp.bottom).offset(0)
            make.left.equalToSuperview()
            make.right.equalToSuperview()
            make.height.equalTo(48.autoWidth())
        }
        xiugai.snp.makeConstraints { (make) in
            make.top.equalTo(youxiang.snp.bottom).offset(0)
            make.left.equalToSuperview()
            make.right.equalToSuperview()
            make.height.equalTo(48.autoWidth())
        }
        yijian.snp.makeConstraints { (make) in
            make.top.equalTo(xiugai.snp.bottom).offset(0)
            make.left.equalToSuperview()
            make.right.equalToSuperview()
            make.height.equalTo(48.autoWidth())
        }
        
        delete.snp.makeConstraints { (make) in
            make.top.equalTo(yijian.snp.bottom).offset(36.autoWidth())
            make.left.equalToSuperview().offset(10.autoWidth())
            make.right.equalToSuperview().offset(-10.autoWidth())
            make.height.equalTo(44.autoWidth())
        }
        
    }
    /** 清除userDefaults所有数据*/
     
    func clearAllUserDefaultsData(){
       let userDefaults = UserDefaults.standard
       let dics = userDefaults.dictionaryRepresentation()
       for key in dics {
           userDefaults.removeObject(forKey: key.key)
       }
       userDefaults.synchronize()
    }

}


class CGQmyView: SYBaseView {
    
    let imgView: UIImageView = {
        let v = UIImageView()
        return v
    }()
    
    let tipText: UILabel = {
        let v = UILabel()
        v.text = "这里什么都没有哦"
        v.font = 15.autoFontSize()
        v.textColor = UIColor(hex: 0x333333)
        return v
    }()
    
    let arrow: UIImageView = {
        let v = UIImageView()
        v.image = UIImage(named: "my_arrow")
        return v
    }()
    
    let subTitle: UILabel = {
        let v = UILabel()
        v.font = 15.autoFontSize()
        v.textColor = UIColor(hex: 0x666666)
        v.textAlignment = .right
        return v
    }()
    var tixianBt: UIButton = {
        let v = UIButton()
        return v
    }()
    
    override func initViews() {
        
        addSubview(imgView)
        addSubview(tipText)
        addSubview(arrow)
        addSubview(lineView)
        addSubview(tixianBt)
        addSubview(subTitle)
        imgView.snp.makeConstraints { (make) in
            make.top.equalToSuperview().offset(16.autoWidth())
            make.left.equalToSuperview().offset(10.autoWidth())
            make.width.equalTo(16.autoWidth())
            make.height.equalTo(16.autoWidth())
        }
        tipText.snp.makeConstraints { (make) in
            make.top.equalToSuperview().offset(16.autoWidth())
            make.left.equalToSuperview().offset(33.autoWidth())
            make.height.equalTo(16.autoWidth())
        }
        subTitle.snp.makeConstraints { (make) in
            make.top.equalToSuperview().offset(16.autoWidth())
            make.left.equalTo(tipText.snp.right).offset(10)
            make.right.equalToSuperview().offset(-16.autoWidth())
            make.height.equalTo(16.autoWidth())
        }
        arrow.snp.makeConstraints { (make) in
            make.top.equalToSuperview().offset(16.autoWidth())
            make.right.equalToSuperview().offset(-10.autoWidth())
            make.width.equalTo(16.autoWidth())
            make.height.equalTo(16.autoWidth())
        }
        lineView.snp.makeConstraints { (make) in
            make.bottom.equalToSuperview()
            make.left.equalToSuperview().offset(10.autoWidth())
            make.right.equalToSuperview().offset(-10.autoWidth())
            make.height.equalTo(0.5.autoWidth())
        }
        tixianBt.snp.makeConstraints { (make) in
            make.edges.equalToSuperview()
        }
    }
    
    
   
}
